package com.shu.timerTask;

import org.junit.Test;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/4/8 10:57
 */

public class TimeTask extends Base {


    @Test
    public void test() throws InterruptedException {

        TimerTask task = new TimerTask() {
            /**
             * The action to be performed by this timer task.
             */
            @Override
            public void run() {
                System.out.println("定时任务执行---" + stopWatch.elapsed(TimeUnit.SECONDS));
                downLatch1.countDown();
            }
        };


        Timer timer = new Timer();
        stopWatch.start();
        timer.schedule(task, 1000);
        System.out.println("---start---" + stopWatch.elapsed(TimeUnit.SECONDS));
        downLatch1.await();

    }
}
